package com.dg.river.core.util;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * @作者：HuYong
 * @时间：2021/11/7 11:56
 * @描述：
 * @修改：
 */
public class StartAtyUtils {

    private static StartAtyUtils startAtyUtils;

    public static StartAtyUtils getInstance() {
        if (startAtyUtils == null) {
            synchronized (StartAtyUtils.class) {
                if (startAtyUtils == null) {
                    startAtyUtils = new StartAtyUtils();
                }
            }
        }
        return startAtyUtils;
    }

    /**
     * 跳转Aty
     *
     * @param tClass
     */
    public void startAty(Context mContext, Class<?> tClass) {
        mContext.startActivity(new Intent(mContext, tClass));
    }

    /**
     * 跳转Aty并传参
     *
     * @param tClass
     * @param bundle
     */
    private void startAty(Context mContext, Class<?> tClass, Bundle bundle) {
        Intent intent = new Intent(mContext, tClass);
        intent.putExtras(bundle);
        mContext.startActivity(intent);
    }

    /**
     * 跳转Aty - 栈顶
     *
     * @param tClass
     */
    private void startAtyForTop(Context mContext, Class<?> tClass, Bundle bundle) {
        Intent intent = new Intent(mContext, tClass)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        mContext.startActivity(intent);
    }
}
